// 导入koa
const  koa = require("koa");
//生成应用
const app = new koa();
// 导入init目录下的config
let initConfig = require('./init/config')
const static = require("koa-static");
const path = require("path");
app.use(static(path.join(__dirname,"public")));
//登录拦截
app.use(async (ctx,next)=>{
    if((ctx.path=="/login") || (ctx.path=="/doLogin")|| (ctx.path=="/doRegister") ||(ctx.path=="/register")){
        await next();
    } else {
        if(ctx.cookies.get("name")) {
            await next();
        } else {
            ctx.redirect("/login");
        }
    }

});
initConfig(app);
//设置监听端口
app.listen(8080);
